﻿using Css_VoteSys.Models.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Css_VoteSys.Service
{
    public class VoteInfoService:IVoteInfoService
    {
        private readonly Css_VoteSysContext _db;

        public VoteInfoService(Css_VoteSysContext db)
        {
            _db = db;
        }

        /// <summary>
        /// 判断用户今天是否已经投了5票
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="currentDate"></param>
        /// <returns></returns>
        public bool Is5Vote(int UserId ) {
            DateTime now = DateTime.Now;
            DateTime currentDate = DateTime.Now.Date;
            //根据用户id查询为空 或者 投票数量小于5
            if (_db.VoteInfos.FirstOrDefault(x => x.UserId == UserId) == null || _db.VoteInfos.FirstOrDefault(x => x.UserId == UserId && x.VoteTime == currentDate).VoteNum < 5) {
                return false;
            }
            return true;
        }
    }
}
